package com.javabean;

import java.util.ArrayList;

public class Student {
	private String no;
	private String name;
	private int age;
	private String sex;
	//将学生的信息封装到ArrayList中
	public static ArrayList list = new ArrayList();
	public String getNo() {
		return no;
	}
	public void setNo(String no) {
		this.no = no;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	//添加student方法
	public static void add(Student st) {
		list.add(st);
	}
	
	//根据no删除学生
	public static void del(String no) {
		//依次对list集合中每一个值进行遍历
		for(int i = 0; i<list.size(); i++) {
				Student st = (Student)list.get(i);
		//如果st的no和传递过来的no相同,那么将该学生信息删除
				if(st.getNo().equals(no)) {
					list.remove(st);
					break;
				}
		}
	}
	
	
	//根据no来返回Student对象
	public static Student get(String no) {
		for(int i = 0; i<list.size(); i++) {
			Student st = (Student)list.get(i);
			if(st.getNo().equals(no)) {
				return st;
			}
		}
		return null;
	}
	
	//修改Student对象的方法
	public static void update(Student st) {
		for(int i = 0; i<list.size(); i++) {
			Student oldst =(Student) list.get(i);
			if(oldst.getNo().equals(st.getNo())) {
				list.remove(oldst);
				list.add(i, st);
				break;
			}
		}
	}
}
